from .database import engine, Base, SessionLocal
from .models import User, Workflow, Node
from .core.password import get_password_hash

def init_db():
    # 创建所有表
    Base.metadata.create_all(bind=engine)
    
    # 创建超级管理员用户
    db = SessionLocal()
    try:
        user = db.query(User).filter(User.username == "admin").first()
        if not user:
            user = User(
                username="admin",
                email="admin@example.com",
                hashed_password=get_password_hash("admin"),
                full_name="Administrator",
                is_active=True,
                is_superuser=True,
            )
            db.add(user)
            db.commit()
    finally:
        db.close()

if __name__ == "__main__":
    init_db() 